package cn.com.czpb.client.module.news.activity;

import android.graphics.Bitmap;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.alibaba.fastjson.JSONObject;
import cn.com.czpb.client.R;
import cn.com.czpb.client.app.ToolBarActivityWhite;
import cn.com.czpb.client.utils.FjsonUtil;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.PageCtrl;

import butterknife.BindView;

/**
 * Created by 猪猪侠 on 2017/10/12.
 */

public class NewsPagerActivity extends ToolBarActivityWhite {
    @BindView(R.id.webview_news_szb)
    WebView mWebView;

    @Override
    public int setMyContentView() {
        return R.layout.fragment_newspager;
    }

    @Override
    public void initView() {
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setAppCacheEnabled(true);
        mWebView.addJavascriptInterface(this,"szbListner");

        mWebView.setVerticalScrollBarEnabled(false); //垂直不显示
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }
        });

    }

    @Override
    public void initData() {
        mWebView.loadUrl("http://nj.99cms.com/demo//web/GJSB_SZB/2016-12/08/7875.html");
    }
    @JavascriptInterface
    public void getInfo(String info) {
        LogUtils.e("getInfo-->"+info);
        JSONObject object = FjsonUtil.parseObject(info);
        String title = object.getString("title");
        String url = object.getString("url");
        LogUtils.e("title-->"+title);
        LogUtils.e("url-->"+url);
        PageCtrl.start2NewsPagerDetailActivity(activity,url,title);

    }

}
